//
// Created by alexa on 5/11/2024.
//

#include "ValidInput.h"

#include <iostream>
#include <conio.h>

namespace vi {
    string inputString(string message) {
        string res = "";
        while (res == "") {
            cout << message << endl;
            getline(cin, res);
        }
        return res;
    }

    int inputInt(string message) {
        int res;
        cout << message;
        while (!(cin >> res)) {
            cin.clear();
            cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
            cout << message;
        }
        return res;
    }

    float inputFloat(string message) {
        float res;
        cout << message;
        while (!(cin >> res)) {
            cin.clear();
            cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
            cout << message;
        }
        return res;
    }

    int inputList(vector<string> list, string message) {
        for (int i = 0; i < list.size(); i++) {
            cout << i + 1 << ". " << list[i] << endl;
        }
        cout << message;
        char pressedKey;
        do {
            pressedKey = _getch();
        } while (pressedKey <= '0' || pressedKey > '0' + list.size());
        return pressedKey - '0';
    }
}